package com.u2b.dispatcher;

import java.util.HashMap;

import javax.annotation.PreDestroy;
import javax.servlet.http.HttpServletRequest;

import com.u2b.business.user.UserService;
import com.u2b.global.utils.Constants;

/*
 * else if不能使用变量,所以不得不使用枚举来解决.在1.7中间支持字符串.Java的switch除了内置的原始类型，也支持枚举类型,但是枚举的话必须保证
 * 所有的类型都是final类型,无法做到
 */
public class UserDispatcher
{

    private final UserService userService;

    public UserDispatcher()
    {

        userService = new UserService();

    }

    public Object dispatcer(String action, HashMap<String, Object> initValues, HttpServletRequest request)
    {
        Object obj = null;

        if (Constants.USER_LOGIN.equals(action))
        {
            // String[] names = new String[]{ "email", "password" };
            obj = userService.login(initValues);
        }
        else if (Constants.USER_REGISTER.equals(action))
        {
            // String[] names = new String[]{ "email", "birthday",
            // "password","gender" };
            obj = userService.Register(initValues);

        }
        else if (Constants.USER_UID.equals(action))
        {
            // String[] names = new String[]{ "uid", "latitude", "longitude" };
            obj = userService.getUserByUid(initValues);

        }
        else if (Constants.USER_SETPASSWORD.equals(action))
        {
            obj = userService.setPassword(initValues);

        }
        else if (Constants.USER_SETMULTIPLE.equals(action))
        {
            obj = userService.settingMultiple(initValues, request);

        }
        else if (Constants.USER_SETEMAIL.equals(action))
        {
            obj = userService.setEmail(initValues);

        }

        else if (Constants.USER_ZONE.equals(action))
        {
            obj = userService.getMyzones(initValues);

        }

        else if (Constants.USER_SETVIDEO.equals(action))
        {
            obj = userService.setVideo(initValues, request);
        }

        return obj;
    }

    @PreDestroy
    public void destory()
    {

    }
}
